package cn.hchaojie.camp.javafx.part0;

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class LoginForm extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		Scene scene = new Scene(createContents(), 300, 150);
		
		stage.setScene(scene);
		stage.show();
	}
	
	// 在这里创建页面布局
	private Parent createContents() {
		GridPane grid = new GridPane();
		
		grid.setAlignment(Pos.CENTER);
		grid.setPadding(new Insets(10));
		grid.setVgap(10);
		grid.setHgap(10);

		Label label = new Label("欢迎登陆，请输入用户名和密码");
		label.setFont(Font.font("微软雅黑", FontWeight.BOLD, 15));
		grid.add(label, 0, 0);
		GridPane.setColumnSpan(label, 2);
		
		Label name = new Label("用户名：");
		grid.add(name, 0, 1);
		GridPane.setConstraints(name, 0, 1, 1, 1, HPos.RIGHT, VPos.CENTER);
		TextField txtName = new TextField();
		grid.add(txtName, 1, 1);
		
		Label password = new Label("密码：");
		grid.add(password, 0, 2);
		GridPane.setConstraints(password, 0, 2, 1, 1, HPos.RIGHT, VPos.CENTER);
		TextField txtPassword = new TextField();
		grid.add(txtPassword, 1, 2);
		
		Button button = new Button("登陆");
		grid.add(button, 1, 3);
		GridPane.setConstraints(button, 1, 3, 1, 1, HPos.RIGHT, VPos.CENTER);
		
		return grid;
	}

	public static void main(String[] args) {
		launch(args);
	}
}
